package com.itheima.tanhua.web;


import com.itheima.tanhua.service.MessagesService;
import com.itheima.tanhua.vo.PageResult;
import com.itheima.tanhua.vo.TodayBestVo;
import com.itheima.tanhua.vo.UserInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {

    @Autowired
    private MessagesService messagesService;


    //展示出用户的基本信息,通过环信的用户id
    @GetMapping("/userinfo")
    public ResponseEntity userinfo(String huaxinId){
        UserInfoVo vo= messagesService.findUserinfo(huaxinId);
        return ResponseEntity.ok(vo);
    }

    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map<String,Long> map){
        Long friendId = map.get("userId");
        messagesService.contacts(friendId);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/contacts")
    public ResponseEntity contactsList(String keyword,@RequestParam(value = "page",defaultValue = "1")Integer page,
                                       @RequestParam(value = "pagesize",defaultValue = "1")Integer pagesize){
        PageResult pageResult=messagesService.contactsList(keyword,page,pagesize);
        return ResponseEntity.ok(pageResult);
    }
    @GetMapping("announcements")
    public PageResult announ(@RequestParam(value = "page", defaultValue = "1") Integer page,
                                 @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize){
        return messagesService.getAllAnnoun(page,pagesize);
    }

    /**
     * 喜欢列表
     * @param page
     * @param pagesize
     * @return
     */
    @GetMapping("/loves")
    public PageResult loves(@RequestParam(value = "page", defaultValue = "1") Integer page,
                             @RequestParam(value = "pagesize", defaultValue = "10") Integer pagesize){
        return messagesService.getAllLoves(page,pagesize);
    }
}
